package com.woniuxy.course.exception;

import com.woniuxy.course.utils.*;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ResponseBody;


/**
 * @author CodingMaster
 * @create 2020-07-25 10:15
 * @description
 */
@ControllerAdvice
public class ExceptionHandler {

    @org.springframework.web.bind.annotation.ExceptionHandler(Exception.class)
    @ResponseBody
    public R error(Exception e){
        e.printStackTrace();;
        return R.error().message("执行了全局异常处理");
    }
    //特定异常
    @org.springframework.web.bind.annotation.ExceptionHandler(NullPointerException.class)
    @ResponseBody
    public R error(NullPointerException e){
        e.printStackTrace();;
        return R.error().message("执行了空指针异常处理");
    }
    //自定义异常
    @org.springframework.web.bind.annotation.ExceptionHandler(GuliException.class)
    @ResponseBody
    public R error(GuliException e){
        e.printStackTrace();;
        return R.error().message(e.getMsg()).code(e.getCode());
    }
}
